home *** CD-ROM | disk | FTP | other *** search
- Path: keats.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c++,comp.lang.eiffel,comp.lang.c,comp.object,comp.software-eng
- Subject: Re: Beware of "C" Hackers -- A rebuttal to Bertrand Meyer
- Date: 19 Mar 1996 09:47:27 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4imrvfINNqjo@keats.ugrad.cs.ubc.ca>
- References: <1995Jul3.034108.4193@rcmcon.com> <3taaha$p8j@ixnews3.ix.netcom.com> <4il72s$ena@news4.digex.net>
- NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
-
- In article <4il72s$ena@news4.digex.net>, Ell <ell@access4.digex.net> wrote:
- >Robert C. Martin (rmartin@oma.com) wrote:
- >: What is "low-level C software"? What are the "special techniques and
- >: tricks"?
- >
- >Imo, bit twiddling, liberal use of unions, and fancy pointer arithmetic
- >when not really necessary.
-
- Bit twiddling is OK when it doesn't involve implementation-defined behavior. I
- don't see why not. On the other hand, if you assume a particular storage layout
- for a bitfield, say, then you are hacking!
-
- IMHO, unions are not used enough by C programmers. A union is the true way to
- implement a generic data type, such as a polymorphic dictionary data structure,
- say, which can store a pointer to an arbitrary structure, as well as any
- integral or floating-point type. How else can you do it efficiently in C other
- than:
-
- typedef union {
- double realval;
- long longval;
- unsigned long ulongval;
- void *ptrval;
- } element;
-
- You can use a structure, but then it takes up extra space.
-
- Some programmers will rather just use void * and then store integers by casting
- them to this void *. That is hacking, because it assumes that a void * has
- enough bits to hold an integer. Whether or not this is true is
- implementation-defined.
-
- Or do you mean by ``liberal use of unions'' a violation whereby one type is
- written in the union and read through another? This calls for undefined
- behavior.
-
- --
-
-